package com.carl.zlds.controller.admin;

import com.carl.zlds.tool.common.PageBO;
import com.carl.zlds.tool.common.result.Result;
import com.carl.zlds.controller.BaseController;
import com.carl.zlds.pojo.dto.SaveGameAccountDTO;
import com.carl.zlds.service.IGameAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author carl
 */
@Slf4j
@RestController(value = "admin.gameAccountController")
@RequestMapping("/admin/1/game-account")
@Api(tags = {"管理端 - 游戏账号管理"})
public class GameAccountController extends BaseController {

    private final IGameAccountService gameAccountService;

    @Autowired
    public GameAccountController(IGameAccountService gameAccountService) {
        this.gameAccountService = gameAccountService;
    }

    @ApiOperation("保存游戏账号")
    @PostMapping(value = "/save")
    public Result<Void> save(@RequestParam(value = "id", defaultValue = "0") Long id,
                             @Valid SaveGameAccountDTO dto) {
        gameAccountService.saveGameAccount(id, dto);
        return Result.success();
    }

    @ApiOperation("删除游戏账号")
    @PostMapping(value = "/delete")
    public Result<Void> delete(@RequestParam("id") Long id) {
        gameAccountService.deleteGameAccount(id);
        return Result.success();
    }

    @ApiOperation("出售游戏账号")
    @PostMapping(value = "/sold")
    public Result<Void> sold(@RequestParam("id") Long id) {
        gameAccountService.soldGameAccount(id);
        return Result.success();
    }

    @ApiOperation("游戏账号列表")
    @GetMapping(value = "/list")
    public Result<Map<String, Object>> list(@RequestParam(value = "gameId", defaultValue = "0") Long gameId,
                                            @RequestParam(value = "status") Integer status,
                                            PageBO pageBO) {
        Map<String, Object> map = gameAccountService.getGameAccountList(gameId, status, pageBO);
        return Result.success(map);
    }
}
